package com.itboye.mengwu.app.ui.main;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.config.GlobalConfig;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.DensityUtil;
import com.itboye.core.utils.SPUtils;
import com.itboye.core.utils.XImageLoader;
import com.itboye.core.utils.XPicasso;
import com.itboye.inageview.RoundImageView;
import com.itboye.mengwu.R;
import com.itboye.mengwu.address.BaseDialogFragment;
import com.itboye.mengwu.app.login.ui.LoginActivity;
import com.itboye.mengwu.app.logincontroller.LoginController;
import com.itboye.mengwu.app.ui.mymeng.IntegerParse;
import com.itboye.mengwu.buy.ui.QueRenDingDan;
import com.itboye.mengwu.data.model.AddShopCartSuccessBean;
import com.itboye.mengwu.data.model.GridViewBean;
import com.itboye.mengwu.data.model.LunBoModel;
import com.itboye.mengwu.data.model.ShopCarBean;
import com.itboye.mengwu.data.model.ShopCarBeanCopy;
import com.itboye.mengwu.data.model.ShopCarBeanCopy.StoreList;
import com.itboye.mengwu.data.model.ShopCarBeanCopy.StoreList.Cart;
import com.itboye.mengwu.data.presenter.AddGoodsPresenter;
import com.itboye.mengwu.data.presenter.GoodsDetailPresenter;
import com.itboye.mengwu.data.presenter.LunBoPresenter;
import com.itboye.mengwu.data.presenter.PayPresenter;
import com.itboye.mengwu.data.presenter.ShopCarPresenter;
import com.itboye.mengwu.goodsdetail.snapscrollview.McoyProductContentPage;
import com.itboye.mengwu.goodsdetail.snapscrollview.McoyProductDetailInfoPage;
import com.itboye.mengwu.goodsdetail.snapscrollview.McoySnapPageLayout;
import com.itboye.mengwu.goodsdetail.snapscrollview.McoySnapPageLayout.McoySnapPage;
import com.itboye.mengwu.ui.shop.FlowLayout;
import com.itboye.mengwu.ui.shop.GoodsDetailsRootBean;
import com.itboye.mengwu.widget.CarouselView;
import com.itboye.mengwu.widget.PagerSlidingTabStrip;
import com.itboye.mengwu.widget.XScrollView;
import com.itboye.shopcar_adapter.ShopXiangQingGridViewAdapter;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.Animator.AnimatorListener;
import com.nineoldandroids.animation.ObjectAnimator;
import com.tencent.connect.common.UIListenerManager.ApiTask;
import com.tencent.mm.sdk.modelmsg.SendMessageToWX;
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
import com.tencent.mm.sdk.modelmsg.WXTextObject;
import com.tencent.mm.sdk.modelmsg.WXWebpageObject;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tencent.open.utils.Util;

public class GoodsDetailActivity extends BaseActivity implements Observer,
		OnClickListener {
	PagerSlidingTabStrip tabs;
	ViewPager pager;
	private McoySnapPageLayout flipLayout;
	TextView new_price;// 最新价格
	TextView old_price, old_price2;// 会员价
	TextView btn_baoyou;// 是否包邮
	TextView btn_fahuo_time;// 发货时间
	// TextView txt_buysum;// 已经购买的人数
	TextView txt_tuwenxiangqing;// 图文详情点击按钮
	TextView txt_goods_name;// 商品名字
	TextView txt_goods_introduction;// 商品简介
	TextView txt_fan;// 返
	TextView txt_fanjia;// 返回的价格
	TextView txt_yuanchan;// 产地
	TextView txt_jianshu;// 库存
	TextView txt_buynum;// 购买人数
	TextView txt_collectionnum;// 收藏人数
	TextView txt_collection;// 收藏
	CarouselView topLunbo;// 轮播图
	ImageView img_collection;// 收藏圖標
	private McoyProductContentPage bottomPage = null;
	private McoyProductDetailInfoPage topPage = null;
	LinearLayout re_collection;
	LunBoPresenter lunBoPresenter;
	ShopCarPresenter presener;
	Intent intent;
	ItemFragment bfrag;
	String[] titles = { "图文详情", "商品评价", "商品咨询" };
	private String pid;
	private String uid;
	TextView addShopcart;
	String imgUrl;
	String id;
	String count;
	String pskuid;
	GoodsDetailPresenter detailPresenter;
	AddGoodsPresenter addGoodsPresenter;
	private ArrayList<ImageView> bmps;
	private GoodsDetailsRootBean bean;
	private boolean isCollection = false;
	RelativeLayout kefuLine;
	RelativeLayout xianzheguige;
	ImageView fanhui, fenxiang, gouwuche;
	RoundImageView imgCountry;
	public static final String EVENT_TYPE_UNKNOWN = BaseActivity.class
			.getName() + "_unknown";
	private PopupWindow window;
	private ImageView shareWeiXinHaoYou;
	private ImageView imgSharePengYouQuan;
	private String APP_ID = "wxae95316b3a4998a6";
	GridView detailgridview;
	private int url[] = { R.drawable.baoyou, R.drawable.time, R.drawable.tui,
			R.drawable.jia, R.drawable.gui, R.drawable.man };
	// private String Countext[] = { "包邮", "24小时发货", "退货补运费", "假就赔", "贵就赔",
	// "慢就赔" };
	private String Countext;
	ShopXiangQingGridViewAdapter adapter1;
	private ArrayList<GridViewBean> list;
	protected JiaRuGouWuCheDialog jiaru;
	Button lijibuy;
	PayPresenter payPresenter;
	String psw;
	RelativeLayout all;
	LinearLayout lin_null;
	int imgid;
	int hasSuk;
	LinearLayout bott;
	RelativeLayout top;
	ImageView imgvip2;

	// ImageView back;
	// TextView txt_title;

	// getCate_id
	public class MyAdapter extends FragmentStatePagerAdapter {
		String[] _titles;

		public MyAdapter(FragmentManager fm, String[] titles) {
			super(fm);
			_titles = titles;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return _titles[position];
		}

		@Override
		public int getCount() {
			return _titles.length;
		}

		@Override
		public Fragment getItem(int position) {
			Fragment bfrag2 = null;
			if (position == 0) {
				bfrag2 = new TuWenXiangQing(pid);
			} else if (position == 1) {
				bfrag2 = new ItemFragment(pid);
			} else if (position == 2) {
				bfrag2 = new FragmentProductASk(pid);
			}
			return bfrag2;
		}
	}

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_goodsdetail;
	}

	@Override
	public void onMyCreate() {
		showProgressDialog("商品详情加载中", true);
		all.setVisibility(View.GONE);
		// 透明状态栏
		getWindow()
				.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		// 透明导航栏
		getWindow().addFlags(
				WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);
		intent = getIntent();
		payPresenter = new PayPresenter(this);
		presener = new ShopCarPresenter(this);
		bean = new GoodsDetailsRootBean();
		addGoodsPresenter = new AddGoodsPresenter(this);
		detailPresenter = new GoodsDetailPresenter(this);
		pid = intent.getStringExtra("pid");
		System.out.println("我的商品id是\t\t\t\t" + pid);
		// lunBoPresenter = new LunBoPresenter(this);
		LunBoModel model = new LunBoModel();
		// model.setPosition(112233);
		// lunBoPresenter.getInfo(model);
		uid = (String) SPUtils.get(this, null, SpPublicParams.UID, "");
		psw = (String) SPUtils.get(this, null, SpPublicParams.PASSWORD, "");
		topPage = new McoyProductDetailInfoPage(this, getLayoutInflater()
				.inflate(R.layout.mcoy_produt_detail_layout, null));
		bottomPage = new McoyProductContentPage(this, getLayoutInflater()
				.inflate(R.layout.mcoy_product_content_page, null));

		flipLayout.setSnapPages(topPage, bottomPage);
		pager = (ViewPager) flipLayout.findViewById(R.id.pager);
		pager.setAdapter(new MyAdapter(getSupportFragmentManager(), titles));
		((PagerSlidingTabStrip) flipLayout.findViewById(R.id.tabs))
				.setViewPager(pager);

		detailgridview = (GridView) flipLayout
				.findViewById(R.id.detailgridview);
		fanhui.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		fenxiang.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onShare();

			}
		});
		lijibuy.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (SPUtils.get(GoodsDetailActivity.this,

				null, SpPublicParams.UID, "") + "" == ""
						|| SPUtils.get(GoodsDetailActivity.this, null,
								SpPublicParams.UID, "") + "" == null) {
					Intent intent = new Intent(GoodsDetailActivity.this,
							LoginActivity.class);
					startActivity(intent);
				} else {
					if (bean != null) {
						jiaru = new JiaRuGouWuCheDialog(bean, true);
						jiaru.show(getSupportFragmentManager(), "");
					}

				}
			}
		});
		gouwuche.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String isDaPeigouString = getIntent()
						.getStringExtra("dapeigou");
				if ("dapeigou".equals(isDaPeigouString)) {
					ByAlert.alert("搭配购暂不支持加入购物车");
					return;
				} else {

					Intent intent1 = new Intent();
					intent1.setAction("finish");
					sendBroadcast(intent1);
					Intent intent2 = new Intent("set");
					intent2.putExtra("index", 3);
					sendBroadcast(intent2);
					finish();
				}

			}
		});
		aboutGoodsDetail();

	}

	private String StoreBF(String string) {

		if ("6102".equals(string)) {
			Countext = "包邮";
			imgid = R.drawable.baoyou;
		}
		if ("6103".equals(string)) {
			Countext = "24小时发货";
			imgid = R.drawable.time;
		}
		if ("6104".equals(string)) {
			Countext = "退货补运费";
			imgid = R.drawable.tui;
		}
		if ("6105".equals(string)) {
			Countext = "假就赔";
			imgid = R.drawable.jia;
		}
		if ("6106".equals(string)) {
			Countext = "贵就赔";
			imgid = R.drawable.gui;
		}
		if ("6107".equals(string)) {
			Countext = "慢就赔";
			imgid = R.drawable.man;
		}
		return Countext;
	}

	public void onViewPager() {
		list = new ArrayList<GridViewBean>();
		if (bean.getService_info().size() == 0) {
			detailgridview.setVisibility(View.GONE);
		} else {
			for (int i = 0; i < bean.getService_info().size(); i++) {
				GridViewBean GVbean = new GridViewBean();
				GVbean.setCountext(StoreBF(bean.getService_info().get(i)));
				GVbean.setUrl(imgid);
				list.add(GVbean);
			}
			adapter1 = new ShopXiangQingGridViewAdapter(list,
					GoodsDetailActivity.this);
			detailgridview.setAdapter(adapter1);
		}

	}

	/**
	 * 商品详情
	 */
	public void aboutGoodsDetail() {
		new_price = (TextView) flipLayout.findViewById(R.id.new_price);// 最新价格
		old_price = (TextView) flipLayout.findViewById(R.id.old_price);// 原价
		old_price2 = (TextView) flipLayout.findViewById(R.id.old_price2);//
		btn_baoyou = (TextView) flipLayout.findViewById(R.id.btn_baoyou);// 是否包邮
		imgvip2 = (ImageView) flipLayout.findViewById(R.id.imgvip2);// 是否包邮
		btn_fahuo_time = (TextView) flipLayout
				.findViewById(R.id.btn_fahuo_time);// 发货时间
		// txt_buysum = (TextView) flipLayout.findViewById(R.id.txt_buysum);//
		// 已经购买的人数
		txt_tuwenxiangqing = (TextView) flipLayout
				.findViewById(R.id.txt_tuwenxiangqing);// 图文详情点击按钮
		txt_goods_name = (TextView) flipLayout
				.findViewById(R.id.txt_goods_name);// 商品名字
		txt_fan = (TextView) flipLayout.findViewById(R.id.txt_fan);// 返
		txt_fanjia = (TextView) flipLayout.findViewById(R.id.txt_fanjia);// 返回的价格
		txt_yuanchan = (TextView) flipLayout.findViewById(R.id.txt_yuanchan);// 产地
		imgCountry = (RoundImageView) flipLayout.findViewById(R.id.imgCountry);// 产地图片
		txt_jianshu = (TextView) flipLayout.findViewById(R.id.txt_jianshu);// 库存
		txt_buynum = (TextView) flipLayout.findViewById(R.id.txt_buynum);// 购买人数
		xianzheguige = (RelativeLayout) flipLayout
				.findViewById(R.id.xianzheguige);
		txt_collectionnum = (TextView) flipLayout
				.findViewById(R.id.txt_collectionnum);// 收藏人数
		topLunbo = (CarouselView) flipLayout.findViewById(R.id.topLunbo);
		xianzheguige.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (SPUtils.get(GoodsDetailActivity.this,

				null, SpPublicParams.UID, "") + "" == "" || SPUtils.get(

				GoodsDetailActivity.this, null,

				SpPublicParams.UID, "") + "" == null) {
					Intent intent = new Intent(GoodsDetailActivity.this,
							LoginActivity.class);
					startActivity(intent);
				} else {
					jiaru = new JiaRuGouWuCheDialog(bean, false);
					jiaru.show(getSupportFragmentManager(), "");
				}
			}
		});
		detailPresenter.queryGoods(pid, uid);
		re_collection.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				LoginController.collection(GoodsDetailActivity.this, null);
			}
		});
		txt_collection.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				LoginController.collection(GoodsDetailActivity.this, null);
			}
		});
		addShopcart.setOnClickListener(new OnClickListener() {// 添加购物车

					@Override
					public void onClick(View v) {
						if (SPUtils.get(GoodsDetailActivity.this,

						null, SpPublicParams.UID, "") + "" == ""
								|| SPUtils.get(GoodsDetailActivity.this, null,
										SpPublicParams.UID, "") + "" == null) {
							Intent intent = new Intent(

							GoodsDetailActivity.this, LoginActivity.class);
							startActivity(intent);
						} else {
							String isDaPeigouString = getIntent()
									.getStringExtra("dapeigou");
							if ("dapeigou".equals(isDaPeigouString)) {
								ByAlert.alert("搭配购暂不支持加入购物车");
								return;
							} else {
								new JiaRuGouWuCheDialog(bean, false).show(
										getSupportFragmentManager(), "");
							}

						}
					}
				});
		detailPresenter.queryGoods(pid, uid);
		kefuLine.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// ByAlert.alert("弹出客服！！");
				// Intent intent = new Intent(GoodsDetailActivity.this,
				// WebActivity.class);

				// WebActivity.class);
				// intent.putExtra("title", "联系客服");
				// intent.putExtra("url",
				// "http://www.moodwo.com/index.php/Webview/kefu?uid="
				// + uid + "&psw=" + psw + "");
				// startActivity(intent);
				Intent intent = new Intent(GoodsDetailActivity.this,
						AcitvityBuyAsk.class);
				intent.putExtra("pid", pid);
				startActivity(intent);

			}
		});
	}

	/**
	 * 分享
	 */
	@SuppressWarnings("deprecation")
	public void onShare() {
		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.item_addd_share, null);
		window = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.WRAP_CONTENT);

		window.setFocusable(true);
		window.setBackgroundDrawable(new BitmapDrawable());
		window.setAnimationStyle(R.style.popupwindow_anim_style);
		window.showAtLocation(findViewById(R.id.kefuLine), Gravity.BOTTOM, 0, 0);

		ImageView shareWeiXinHaoYou = (ImageView) view
				.findViewById(R.id.shareWeiXinHaoYou);
		shareWeiXinHaoYou.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// ByAlert.alert("微信好友分享");
				onPengYou();
			}
		});
		ImageView imgSharePengYouQuan = (ImageView) view
				.findViewById(R.id.imgSharePengYouQuan);
		imgSharePengYouQuan.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// ByAlert.alert("微信朋友圈分享");

				onPengYouQuan();
			}
		});
	}

	@SuppressWarnings("deprecation")
	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			Log.e("hu", "! null");
			if (entity.getEventType() == GoodsDetailPresenter.GoodsDetail_Query_SUCCESS) {
				bean = (GoodsDetailsRootBean) entity.getData();
				// if (bean != null && bean.getImgs().size() != 0) {
				all.setVisibility(View.VISIBLE);
				new_price.setText("￥" + bean.getMinPrice());// 最新价格
				old_price.setText("￥" + bean.getMinOriPrice());// 原价
				// old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
				//
				if (bean.getSkuList() != null) {
					if (!bean.getMax_member_price().equals("0")) {
						old_price2.setText("￥" + bean.getMax_member_price());// 会员价

					} else {
						// imgvip2.setVisibility(View.GONE);
						// old_price2.setVisibility(View.GONE);
						old_price2.setText("￥" + bean.getMinOriPrice());// 原价
					}
				} else {
					if (!bean.getMin_member_price().equals("0")) {
						old_price2.setText("￥" + bean.getMin_member_price());// 会员价
						// old_price2.getPaint().setFlags(
						// Paint.STRIKE_THRU_TEXT_FLAG);
					} else {
						old_price2.setText("￥" + bean.getMinOriPrice());// 原价
					}
					// old_price2.setText("￥" + bean.getMin_member_price());//
					// 会员价
				}
				// old_price2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
				// old_price2.setText("￥" + bean.getMinPrice());// 会员价

				DecimalFormat format = new DecimalFormat("#0");
				try {
					double new_p = Double.parseDouble(bean.getStoreBenefit()
							.getCondition());
					double old_p = Double.parseDouble(bean.getStoreBenefit()
							.getDiscountMoney());
					txt_fanjia.setText("满" + format.format(new_p) + "减"
							+ format.format(old_p));
					btn_baoyou.setText("满"
							+ bean.getStoreBenefit().getFreeShipping() + "包邮");
				} catch (Exception e) {
					// TODO: handle exception
				}

				onViewPager();

				// if (bean.getService_info().size() > 0) {
				// txt_buysum.setText(bean.getTotalSales() + "人已购买");//
				// 已经购买的
				// txt_tuwenxiangqing.setText("图文详情");// 图文详情点击按钮
				txt_goods_name.setText(bean.getName());// 商品名字
				// txt_goods_introduction.setText(bean.getSynopsis());//
				// 商品简介
				txt_yuanchan.setText(bean.getOriginCountryName() + "原产");// 产地
				XImageLoader.load(bean.getOrigin_country_img(), imgCountry);
				txt_jianshu.setText(bean.getRemain() + "件");// 库存
				txt_buynum.setText(bean.getTotalSales() + "");// 购买人数
				txt_collectionnum.setText(bean.getFavs() + "");// 收藏人数
				if (bean.getImgs() != null && bean.getImgs().size() > 0) {
					bmps = new ArrayList<ImageView>();
					for (int i = 0; i < bean.getImgs().size(); i++) {
						ImageView imageView = new ImageView(this);
						imageView.setScaleType(ScaleType.FIT_XY);
						// com.nostra13.universalimageloader.core.ImageLoader
						// .getInstance().displayImage(
						// GlobalConfig.API_URL
						// + "/picture/index?id="
						// + bean.getImgs().get(i),
						// imageView);
						XPicasso.loadImage(this, imageView,
								GlobalConfig.API_URL + "/picture/index?id="
										+ bean.getImgs().get(i));
						bmps.add(imageView);
						imageView.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
							}
						});
					}
					topLunbo.setImageBitmaps(bmps);
				} else {
					ImageView imageView = new ImageView(this);
					imageView.setScaleType(ScaleType.FIT_XY);
					bmps = new ArrayList<ImageView>();
					com.nostra13.universalimageloader.core.ImageLoader
							.getInstance().displayImage(
									GlobalConfig.API_URL + "/picture/index?id="
											+ bean.getMainImg(), imageView);
					bmps.add(imageView);
					topLunbo.setImageBitmaps(bmps);
				}
				isCollection = (bean.getIsFav() == 1 ? true : false);
				if (isCollection) {
					img_collection.setImageResource(R.drawable.collection_yi);
					txt_collection.setText("已收藏");
				} else {
					img_collection.setImageResource(R.drawable.collection_un);
					txt_collection.setText("未收藏");
				}
				// } else {
				// all.setVisibility(View.GONE);
				// }
			} else if (entity.getEventType() == ShopCarPresenter.ShopCarAdd_success) {
				AddShopCartSuccessBean addShopCartSuccessBean = (AddShopCartSuccessBean) entity
						.getData();
				ByAlert.alert(addShopCartSuccessBean.getMsg() + "");
				Intent intent = new Intent("changeshopcart");
				sendBroadcast(intent);
				jiaru.dismiss();
			} else if (entity.getEventType() == ShopCarPresenter.ShopCarAddFailEvent) {
				ByAlert.alert("添加失败");
			} else if (entity.getEventType() == LunBoPresenter.BannerSuccessEvent) {
				bean = (GoodsDetailsRootBean) entity.getData();
				ByAlert.alert(bean + "");
			} else if (entity.getEventType() == GoodsDetailPresenter.GoodsDetail_Query_FAILE) {
				all.setVisibility(View.GONE);
			} else if (entity.getEventType() == AddGoodsPresenter.AddGoodsToCollection_success) {
				if ((entity.getData() + "").equals("取消收藏成功！")) {
					ByAlert.alert("取消收藏成功");
					img_collection.setImageResource(R.drawable.collection_un);
					txt_collection.setText("未收藏");
				} else {
					ByAlert.alert("收藏成功");
					img_collection.setImageResource(R.drawable.collection_yi);
					txt_collection.setText("已收藏");
				}
				isCollection = !isCollection;
			} else if (entity.getEventType() == AddGoodsPresenter.AddGoodsToCollection_fail) {
				ByAlert.alert("操作失败，请检查网络");
			} else {
				all.setVisibility(View.VISIBLE);
				top.setVisibility(View.GONE);
				bott.setVisibility(View.GONE);
				flipLayout.setVisibility(View.GONE);
				lin_null.setVisibility(View.VISIBLE);
				TextView tv = (TextView) lin_null.findViewById(R.id.tv);
				tv.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	/***
	 * 收藏方法
	 */
	public void collection() {
		if (isCollection) {
			addGoodsPresenter.addCollection(uid, pid, 0);
		} else {
			addGoodsPresenter.addCollection(uid, pid, 1);
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		default:
			break;
		}
	}

	public void onPengYou() {
		// 初始化一个WXTextObject对象
		// final IWXAPI api = WXAPIFactory.createWXAPI(this, APP_ID, true);
		// api.registerApp(APP_ID);
		// api.openWXApp();
		// String text = "分享一件好商品，速来围观";
		// WXTextObject textObj = new WXTextObject();
		// textObj.text = text;
		// WXMediaMessage msg = new WXMediaMessage(textObj);
		// msg.mediaObject = textObj;
		// msg.description = text;
		// SendMessageToWX.Req req = new SendMessageToWX.Req();
		// req.transaction = String.valueOf(System.currentTimeMillis());
		// req.message = msg;
		// req.scene = SendMessageToWX.Req.WXSceneTimeline;
		// api.sendReq(req);
		final IWXAPI api = WXAPIFactory.createWXAPI(this, APP_ID, true);
		api.registerApp(APP_ID);
		api.openWXApp();
		WXWebpageObject webpage = new WXWebpageObject();
		webpage.webpageUrl = "http://www.moodwo.com/index.php/Webview/product/detail?uid="
				+ uid + "&psw=" + psw + "&id=" + pid;
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = "萌屋分享";
		msg.description = "我在萌屋发现了一个好玩的东西，速来围观";
		// Bitmap thumb = BitmapFactory.decodeResource(
		// getResources(), R.drawable.logo);
		// msg.thumbData=Util.bmpToByteArray(thumb,true);
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = "webpage";
		req.message = msg;
		req.scene = SendMessageToWX.Req.WXSceneSession;
		api.sendReq(req);
	}

	public void onPengYouQuan() {
		// 初始化一个WXTextObject对象
		// final IWXAPI api = WXAPIFactory.createWXAPI(this, APP_ID, true);
		// api.registerApp(APP_ID);
		// api.openWXApp();
		// String text = "分享一件好商品，速来围观";
		// WXTextObject textObj = new WXTextObject();
		// textObj.text = text;
		// WXMediaMessage msg = new WXMediaMessage(textObj);
		// msg.mediaObject = textObj;
		// msg.description = text;
		// SendMessageToWX.Req req = new SendMessageToWX.Req();
		// req.transaction = String.valueOf(System.currentTimeMillis());
		// req.message = msg;
		// req.scene = SendMessageToWX.Req.WXSceneSession;
		// api.sendReq(req);
		final IWXAPI api = WXAPIFactory.createWXAPI(this, APP_ID, true);
		api.registerApp(APP_ID);
		api.openWXApp();
		WXWebpageObject webpage = new WXWebpageObject();
		webpage.webpageUrl = "http://www.moodwo.com/index.php/Webview/product/detail?uid="
				+ uid + "&psw=" + psw + "&id=" + pid;
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = "我在萌屋发现了一个好玩的东西，速来围观";
		msg.description = "我在萌屋发现了一个好玩的东西，速来围观";
		// Bitmap thumb = BitmapFactory.decodeResource(
		// getResources(), R.drawable.logo);
		// msg.thumbData=Util.bmpToByteArray(thumb,true);
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = "webpage";
		req.message = msg;
		req.scene = SendMessageToWX.Req.WXSceneTimeline;
		api.sendReq(req);

	}

	class JiaRuGouWuCheDialog extends BaseDialogFragment {
		View close;
		ImageView pic;
		TextView jiege;
		TextView kucun;
		ViewGroup guigeContainer;
		View ok;
		GoodsDetailsRootBean goodsDetailBeans;
		View jian;
		View jia;
		EditText input;
		boolean isLiJIGouMai;
		ViewGroup container;
		String imgUrl;
		protected String price;
		protected String skuId;

		public JiaRuGouWuCheDialog() {

		}

		public JiaRuGouWuCheDialog(GoodsDetailsRootBean goodsDetailBeans,
				boolean isLiJIGouMai) {

			this.goodsDetailBeans = goodsDetailBeans;
			this.isLiJIGouMai = isLiJIGouMai;
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {

			return LayoutInflater.from(getContext()).inflate(
					R.layout.dialogfragment_jiarugouwuche, null);
		}

		@Override
		public void onActivityCreated(Bundle savedInstanceState) {

			super.onActivityCreated(savedInstanceState);

			if (savedInstanceState != null) {
				goodsDetailBeans = (GoodsDetailsRootBean) savedInstanceState
						.getSerializable("goodsDetailBeans");
				isLiJIGouMai = savedInstanceState.getBoolean("isLiJIGouMai");
			}
			imgUrl = goodsDetailBeans.getMainImg();
			XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
					+ goodsDetailBeans.getMainImg(), pic);
			if (goodsDetailBeans.getSkuInfo() != null) {
				if (goodsDetailBeans.getSkuInfo().getMemberPrice() != null
						&& !goodsDetailBeans.getSkuInfo().getMemberPrice()
								.equals("0.00")) {
					jiege.setText("会员价   ￥"
							+ goodsDetailBeans.getSkuInfo().getMemberPrice());
				} else {
					jiege.setText("￥" + goodsDetailBeans.getMinPrice());

				}
			} else {

			}
			if (goodsDetailBeans.getHasSku() != null) {
				hasSuk = goodsDetailBeans.getHasSku();
				if (hasSuk == 1) {// 多规格
					addGuiGe();
				} else {// 单规格
					((View) kucun.getParent()).setVisibility(View.VISIBLE);
					if (goodsDetailBeans.getSkuInfo() != null) {
						kucun.setText(goodsDetailBeans.getRemain() + "");
					}
				}
			}
			jia.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					String s = input.getText().toString();
					try {
						int c = Integer.parseInt(s);
						input.setText(c + 1 + "");
					} catch (NumberFormatException e) {
						input.setText("1");
					}
					input.setSelection(input.getText().length());
				}
			});
			jian.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					String s = input.getText().toString();
					try {
						int c = Integer.parseInt(s);
						if (c > 0) {
							c--;
						}
						input.setText(c + "");
					} catch (NumberFormatException e) {
						input.setText("0");
					}
					input.setSelection(input.getText().length());
				}
			});
			close.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					close();
				}
			});
			ok.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {

					String s = checkGuiGeSelectedState();
					if (s == null) {
						return;
					}
					if (input.getText().length() > 3) {
						ByAlert.alert("别闹，买那么多干吗");
						return;
					}
					String tString = kucun.getText().toString();
					String string = input.getText().toString();
					System.out.println(tString + "tString" + string);
					if (Integer.parseInt(kucun.getText().toString()) < Integer
							.parseInt(input.getText().toString())) {
						Toast.makeText(getContext(), "库存不足", 1).show();
						return;
					}
					int hasSuk = goodsDetailBeans.getHasSku();
					String pskuId = "";
					if (hasSuk == 1) {
						List<GoodsDetailsRootBean.SkuList> list = goodsDetailBeans
								.getSkuList();
						for (GoodsDetailsRootBean.SkuList skuCombinationBean : list) {
							if (skuCombinationBean.getSkuId().equals(s)) {
								pskuId = skuCombinationBean.getId();
								break;
							}
						}
					} else {
						if (goodsDetailBeans.getSkuInfo() != null
								&& goodsDetailBeans.getSkuList() == null) {
							pskuId = goodsDetailBeans.getSkuInfo().getId();
							Log.e("hu=pskid", goodsDetailBeans.getSkuInfo()
									.getId());
						}
					}
					ok.setEnabled(false);

					uid = (String) SPUtils.get(getContext(), null,
							SpPublicParams.UID, "");
					// pid = pskuId;
					id = goodsDetailBeans.getId();
					count = input.getText().toString();
					pskuid = pskuId;
					System.out.println(">>oskuif" + pskuid);
					if (!isLiJIGouMai) {// 加入购物车
						if (hasSuk == 1) {
							ShopCarBean model = new ShopCarBean();
							model.setUid(uid);// 暫時代替uid
							model.setId(goodsDetailBeans.getId());// 暫時代替pid
							model.setCount(input.getText().toString());// 暫時代替count
							model.setPskuId(skuId);// 暫時代替 psku_id
							presener.add(model);
						} else {
							ShopCarBean model = new ShopCarBean();
							model.setUid(uid);// 暫時代替uid
							model.setId(goodsDetailBeans.getSkuInfo()
									.getProductId());// 暫時代替pid
							model.setCount(input.getText().toString());// 暫時代替count
							model.setPskuId(goodsDetailBeans.getSkuInfo()
									.getId());// 暫時代替 psku_id
							presener.add(model);
						}

					} else {// 立即购买
						ShopCarBeanCopy.StoreList store = new StoreList();
						Intent intent = new Intent(getActivity(),
								QueRenDingDan.class);
						List<StoreList.Cart> storeList = new ArrayList<>();
						if (hasSuk == 1) {
							Cart cart = new Cart();
							cart.setPrice(price);
							cart.setPId(pid);
							cart.setIconUrl(imgUrl);
							cart.setPskuId(pskuId);
							cart.setName(goodsDetailBeans.getName());
							cart.setCount(input.getText().toString());

							storeList.add(cart);
							store.setId(bean.getStoreId());
							store.setCarts(storeList);
						} else {
							Cart cart = new Cart();
							cart.setPrice(goodsDetailBeans.getSkuInfo()
									.getPrice());
							cart.setPId(goodsDetailBeans.getSkuInfo()
									.getProductId());
							cart.setIconUrl(imgUrl);
							cart.setPskuId(pskuId);
							cart.setName(goodsDetailBeans.getName());
							cart.setCount(input.getText().toString());
							storeList.add(cart);
							store.setId(bean.getStoreId());
							store.setCarts(storeList);
						}
						intent.putExtra("model", store);
						intent.putExtra("isLiJiBuy", isLiJIGouMai);
						startActivity(intent);
					}
					dismiss();
				}
			});
			pic.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (imgUrl != null) {
						// ImageViewerDialog imageViewerDialog = new
						// ImageViewerDialog(
						// getActivity());
						// String urls[] = new String[] { imgUrl };
						// imageViewerDialog.setImageUrls(urls);
						// imageViewerDialog.show(0);
					}

				}
			});
		}

		public ResultEntity handlerError(Object data) {
			ResultEntity result = (ResultEntity) data;
			if (result == null) {
				result = new ResultEntity("-1", "数据格式错误!~", data);
				return result;
			}

			if (result.hasError()) {
				ByAlert.alert(result.getMsg());
				result.setEventType(EVENT_TYPE_UNKNOWN);
				return result;
			}
			return result;
		}

		protected String checkGuiGeSelectedState() {

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < guigeContainer.getChildCount(); i++) {
				View vv = guigeContainer.getChildAt(i);
				if (!(vv instanceof FlowLayout)) {
					continue;
				}
				FlowLayout flowLayout = (FlowLayout) vv;
				int j;
				for (j = 0; j < flowLayout.getChildCount(); j++) {
					TextView textView = (TextView) flowLayout.getChildAt(j);
					if (textView.isSelected()) {
						sb.append(textView.getTag() + ";");
						break;
					}
				}
				if (j == flowLayout.getChildCount()) {
					Toast.makeText(
							getContext(),
							"请选择"
									+ goodsDetailBeans.getSkuName().get(i / 2)
											.getId(), 1).show();
					return null;
				}
			}
			return sb.toString();
		}

		private void addGuiGe() {

			List<GoodsDetailsRootBean.SkuName> list = goodsDetailBeans
					.getSkuName();
			for (int i = 0; i < list.size(); i++) {
				GoodsDetailsRootBean.SkuName skuBean = list.get(i);
				TextView title = createTitle(skuBean.getId());
				guigeContainer.addView(title);

				FlowLayout flowLayout = createFlowLayout(skuBean.getVid(),
						goodsDetailBeans.getSkuId().get(i).getId() + "",
						goodsDetailBeans.getSkuId().get(i).getVid());
				guigeContainer.addView(flowLayout);
			}
			container.getViewTreeObserver().addOnGlobalLayoutListener(
					new OnGlobalLayoutListener() {

						@SuppressWarnings("deprecation")
						@SuppressLint("NewApi")
						@Override
						public void onGlobalLayout() {
							try {
								container.getViewTreeObserver()
										.removeGlobalOnLayoutListener(this);
							} catch (Throwable e) {
							}
							if (container.getHeight() > DensityUtil
									.screenHeigh() * 0.7) {

								int h = DensityUtil.screenHeigh()
										- DensityUtil.dip2px(280);
								XScrollView scrollView = new XScrollView(
										getContext());
								scrollView.setLayoutParams(new LayoutParams(
										LayoutParams.MATCH_PARENT, h));

								ViewGroup vg = (ViewGroup) guigeContainer
										.getParent();
								vg.removeView(guigeContainer);

								scrollView.addView(guigeContainer);
								vg.addView(scrollView);
							}
						}
					});
		}

		private OnClickListener clickListener = new OnClickListener() {

			@Override
			public void onClick(View v) {

				try {
					kucun.setText(null);
					jiege.setText(null);
					if (v.isSelected()) {
						v.setSelected(false);
						((TextView) v).setTextColor(Color.BLACK);
						imgUrl = goodsDetailBeans.getMainImg();
						if ((!goodsDetailBeans.imgs.isEmpty())
								& goodsDetailBeans.imgs != null) {
							XImageLoader.load(
									GlobalConfig.API_URL + "/picture/index?id="
											+ goodsDetailBeans.getMainImg(),
									pic);
						}
						return;
					}
					FlowLayout clickTextViewParent = null;
					StringBuilder stringBuilder = new StringBuilder();

					for (int i = 0; i < guigeContainer.getChildCount(); i++) {
						View view = guigeContainer.getChildAt(i);
						if (!(view instanceof FlowLayout)) {
							continue;
						}
						FlowLayout flowLayout = (FlowLayout) view;
						if (v.getParent() == flowLayout) {
							clickTextViewParent = flowLayout;
							stringBuilder.append(v.getTag());
							stringBuilder.append(";");

						} else {
							for (int j = 0; j < flowLayout.getChildCount(); j++) {
								View textview = flowLayout.getChildAt(j);
								if (textview.isSelected()) {
									stringBuilder.append(textview.getTag());
									stringBuilder.append(";");
									break;
								}
							}
						}
					}
					List<GoodsDetailsRootBean.SkuList> skuList = goodsDetailBeans
							.getSkuList();
					String selectedSku = stringBuilder.toString();
					for (GoodsDetailsRootBean.SkuList skuCombinationBean : skuList) {
						String sku = skuCombinationBean.getSkuId();

						if (sku.contains(selectedSku)) {
							for (int j = 0; j < clickTextViewParent
									.getChildCount(); j++) {
								if (clickTextViewParent.getChildAt(j)
										.isSelected()) {
									clickTextViewParent.getChildAt(j)
											.setSelected(false);
									((TextView) clickTextViewParent
											.getChildAt(j))
											.setTextColor(Color.BLACK);
									break;
								}
							}
							v.setSelected(true);
							((TextView) v).setTextColor(Color.WHITE);
							break;
						}
					}
					String s = isAllFenLeiSelected();
					if (s != null) {
						((View) kucun.getParent()).setVisibility(View.VISIBLE);
						List<GoodsDetailsRootBean.SkuList> list = goodsDetailBeans
								.getSkuList();
						for (GoodsDetailsRootBean.SkuList skuCombinationBean : list) {
							if (skuCombinationBean.getSkuId().equals(s)) {
								kucun.setText(skuCombinationBean.getQuantity()
										+ "");
								price = skuCombinationBean.getPrice();
								if (!skuCombinationBean.getMemberPrice()
										.equals("0.00")
										&& !skuCombinationBean.getMemberPrice()
												.equals("")) {
									price = skuCombinationBean.getMemberPrice();
									jiege.setText("会员价    ￥"
											+ skuCombinationBean
													.getMemberPrice());
								} else {
									price = skuCombinationBean.getPrice();
									jiege.setText("￥"
											+ skuCombinationBean.getPrice());
								}
								skuId = skuCombinationBean.getId();

								if (TextUtils.isEmpty(skuCombinationBean
										.getIconUrl())) {
									XImageLoader.load(GlobalConfig.API_URL
											+ "/picture/index?id="
											+ goodsDetailBeans.getMainImg(),
											pic);
									imgUrl = goodsDetailBeans.getMainImg();
								} else {
									XImageLoader.load(GlobalConfig.API_URL
											+ "/picture/index?id="
											+ skuCombinationBean.getIconUrl(),
											pic);
									imgUrl = skuCombinationBean.getIconUrl();
								}
								break;
							}
						}
					} else {
						((View) kucun.getParent())
								.setVisibility(View.INVISIBLE);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};

		private String isAllFenLeiSelected() {
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < guigeContainer.getChildCount(); i++) {
				View vv = guigeContainer.getChildAt(i);
				if (!(vv instanceof FlowLayout)) {
					continue;
				}
				FlowLayout flowLayout = (FlowLayout) vv;
				int j;
				for (j = 0; j < flowLayout.getChildCount(); j++) {
					TextView textView = (TextView) flowLayout.getChildAt(j);
					if (textView.isSelected()) {
						sb.append(textView.getTag() + ";");
						break;
					}
				}
				if (j == flowLayout.getChildCount()) {
					return null;
				}
			}
			return sb.toString();
		}

		/**
		 * 当前已选中的规格集合
		 * 
		 * @return
		 */
		protected List<String> selectedGuige() {

			List<String> selectedGuige = new ArrayList<String>();
			for (int i = 0; i < guigeContainer.getChildCount(); i++) {
				View vv = guigeContainer.getChildAt(i);
				if (!(vv instanceof FlowLayout)) {
					continue;
				}
				FlowLayout flowLayout = (FlowLayout) vv;
				for (int j = 0; j < flowLayout.getChildCount(); j++) {
					TextView textView = (TextView) flowLayout.getChildAt(j);
					if (textView.isSelected()) {
						selectedGuige.add((String) textView.getTag());
					}
				}
			}
			return selectedGuige;
		}

		private FlowLayout createFlowLayout(List<String> vid, String id,
				List<String> vids) {
			int dis = DensityUtil.dip2px(5);
			FlowLayout flowLayout = new FlowLayout(getContext());
			for (int i = 0; i < vid.size(); i++) {
				TextView textView = new TextView(getContext());
				textView.setTextColor(Color.BLACK);
				textView.setBackgroundResource(R.drawable.selector_guige);
				textView.setText(vid.get(i));
				textView.setTag(id + ":" + vids.get(i));
				textView.setOnClickListener(clickListener);
				ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(
						ViewGroup.LayoutParams.WRAP_CONTENT,
						ViewGroup.LayoutParams.WRAP_CONTENT);
				marginLayoutParams.setMargins(dis, dis, dis, dis);
				textView.setLayoutParams(marginLayoutParams);
				flowLayout.addView(textView);
			}
			return flowLayout;
		}

		/**
		 * 设置套餐一、套餐二等标题栏
		 * 
		 * @param s
		 * @return
		 */
		private TextView createTitle(String s) {
			TextView textView = new TextView(getContext());
			textView.setText(s);
			textView.setTextColor(Color.BLACK);
			return textView;
		}

		public void close() {
			View v = getView().findViewById(R.id.container);
			ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationY",
					0, v.getHeight()).setDuration(300);
			animator.addListener(new AnimatorListener() {
				@Override
				public void onAnimationStart(Animator arg0) {
				}

				@Override
				public void onAnimationRepeat(Animator arg0) {
				}

				@Override
				public void onAnimationEnd(Animator arg0) {
					dismiss();
				}

				@Override
				public void onAnimationCancel(Animator arg0) {
					dismiss();
				}
			});
			animator.start();
		}

		@Override
		public void onSaveInstanceState(Bundle arg0) {
			super.onSaveInstanceState(arg0);
			// arg0.putSerializable("goodsDetailBeans", goodsDetailBeans);
			// arg0.putBoolean("isLiJIGouMai", isLiJIGouMai);
		}

	}

	class TuWenXiangQing extends BaseFragment implements McoySnapPage {
		// FoundWebView web;
		WebView web;
		private String urls = "http://www.moodwo.com/index.php/Webview/";
		private String pid;
		WebSettings settings;
		ProgressBar myProgressBar;
		String uid;
		String psw;
		private boolean isAtTop;
		private boolean isIdle;
		float old_x;
		float old_y;

		public TuWenXiangQing(String pid) {
			// TODO Auto-generated constructor stub
			this.pid = pid;
		}

		@Override
		public int initView() {
			// TODO Auto-generated method stub
			return R.layout.fragment_tuwenxiangqing;
		}

		@Override
		public void onMyActivityCreated() {
			// TODO Auto-generated method stub
			uid = (String) SPUtils.get(getActivity(), null, SpPublicParams.UID,
					"");
			psw = (String) SPUtils.get(getActivity(), null,
					SpPublicParams.PASSWORD, "");
			settings = web.getSettings();
			settings.setSupportZoom(true);
			settings.setJavaScriptEnabled(true);
			settings.setUseWideViewPort(true);
			settings.setLoadWithOverviewMode(true);
			web.setWebViewClient(new WebViewClient() {

				@Override
				public boolean shouldOverrideUrlLoading(WebView view, String url) {
					// TODO Auto-generated method stub
					return true;
				}
			});
			// web.setOnCustomScroolChangeListener(new ScrollInterface() {
			//
			// @Override
			// public void onSChanged(int l, int t, int oldl, int oldt) {
			// // TODO Auto-generated method stub
			// float webcontent = web.getContentHeight() * web.getScale();//
			// webview的高度
			//
			// float webnow = web.getHeight() + web.getScrollY();// 当前webview的高度
			// if (web.getContentHeight() * web.getScale()
			// - (web.getHeight() + web.getScrollY()) <= 0) {
			// flipLayout.requestDisallowInterceptTouchEvent(true);
			// // 已经处于底端
			// Log.e("hu---", "b");
			// } else {
			// Log.e("hu---", "t1");
			// flipLayout.requestDisallowInterceptTouchEvent(false);
			// }
			// // 已经处于顶端
			// if (web.getScaleY() == 0) {
			// Log.e("hu---2", "t");
			// }
			// // }});
			// }
			// });
			web.setOnTouchListener(new OnTouchListener() {

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					if (event.getAction() == MotionEvent.ACTION_UP) {
						(flipLayout).requestDisallowInterceptTouchEvent(false);
					} else {
						(flipLayout).requestDisallowInterceptTouchEvent(true);
					}
					float webcontent = web.getContentHeight() * web.getScale();
					// webview的高度
					float webnow = web.getHeight() + web.getScrollY();// 当前webview的高度
					Log.e("hu==", webcontent + ",now=" + webnow);
					if (web.getContentHeight() * web.getScale()
							- (web.getHeight() + web.getScrollY()) <= 0) {
						// 已经处于底端
						Log.e("hu---", "b");
					}
					DisplayMetrics dm = new DisplayMetrics();
					getWindowManager().getDefaultDisplay().getMetrics(dm);
					if (webnow <= web.getHeight()) {
						(flipLayout).requestDisallowInterceptTouchEvent(false);
					}

					Log.e("hu---3", "t1=" + web.getContentHeight() + ",t2="
							+ web.getScale() + ",t3=" + web.getScaleY()
							+ ",t4=" + web.getHeight());
					return false;
				}
			});

			web.loadUrl(urls + "product/detail?uid=" + uid + "&psw=" + psw
					+ "&id=" + pid);
			Log.e("hu--tuwen", urls + "product/detail?uid=" + uid + "&psw="
					+ psw + "&id=" + pid);
		}

		@Override
		public View getRootView() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public boolean isAtTop() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isAtBottom() {
			// TODO Auto-generated method stub
			return isAtTop;
		}

	}
}
